package com.gitee.cirnochat.login.model.vo.resp;

import com.gitee.cirnochat.login.model.entity.LoginHistory;
import com.gitee.cirnochat.login.model.enums.DeviceType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@Schema(description = "登录历史记录视图对象")
@NoArgsConstructor
public class LoginHistoryVo implements Serializable {
    /**
     * 主键ID
     */
    @Schema(description = "登陆历史ID", example = "1141241124214")
    private Long id;
    /**
     * 设备ID
     */
    @Schema(description = "设备ID", example = "device-123456")
    private String deviceId;

    /**
     * 设备名称
     */
    @Schema(description = "设备名称", example = "小米手机")
    private String deviceName;

    /**
     * 设备类型
     */
    @Schema(description = "设备类型", example = "0:未知 1:手机 2:平板 3:电脑 4:电视 5:web浏览器")
    private DeviceType deviceType;

    /**
     * IP地址
     */
    @Schema(description = "IP地址", example = "113.123.12.31")
    private String ipAddress;

    /**
     * IP地址描述
     */
    @Schema(description = "IP地址描述", example = "中国|广东省|广州市")
    private String ipDescription;

    /**
     * 是否登陆成功 0:失败 1:成功
     */
    @Schema(description = "是否登陆成功", example = "true")
    private Boolean status;

    /**
     * 登陆时间
     */
    @Schema(description = "登陆时间", example = "2024-01-01T12:00:00")
    private LocalDateTime loginTime;

    public LoginHistoryVo(LoginHistory loginHistory) {
        BeanUtils.copyProperties(loginHistory, this);
        this.status = loginHistory.getStatus() == 1;
    }

    private static final long serialVersionUID = 1L;
}
